<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <ul>
      <li v-for="cate in cates" :key="cate.id">
        <img :src="cate.icon" alt="">
        <h5>{{cate.name}}</h5>
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>
  <script>

    
    const request = axios.create({
      baseURL: 'https://api.it120.cc/conner',
      timeout: 6000,
      headers: {
        a: 'dwdwfegrjyu7'
      }
    })

    request.interceptors.request.use(function(config) {
      console.log('请求发送了',  config);
      return config;
    },function(error) {

      return Promise.reject(error);
    });

    // Add a response interceptor
    request.interceptors.response.use(function(response) {
      console.log('数据响应了', response);
      return response;
    },function(error) {

      return Promise.reject(error);
    });
    const vm = new Vue({
      el: '#app',
      data: {
        cates: []
      },
      methods: {
        fetchCates() {
          // 发送get请求
          request.get('/shop/goods/category/all?a=10&b=20').then(res => {
            if (res.data.code === 0) {
              this.cates = res.data.data
            }
          })
        }
      },
      created() {
        this.fetchCates();
      }
    })
  </script>
</body>

</html>